package com.happycat.controller.social;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.happycat.base.PageParams;
import com.happycat.base.R;
import com.happycat.social.dto.SocialFollowFriendsQueryDto;
import com.happycat.social.dto.SocialFollowSaveDto;
import com.happycat.social.service.ISocialFollowService;
import com.happycat.social.vo.FollowVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/social/follow")
@Api(tags = "API-关注功能", value = "关注功能", description = "好友/黑名单关系")
public class FollowController {

    @Autowired
    public ISocialFollowService followService;

    @PostMapping(value = "/addFollow")
    @ApiOperation(value = "添加关注/黑名单", notes = "若已是黑名单，再次进行关注，将移除黑名单并且关注")
    public R<Boolean> addFollow(@Valid @RequestBody SocialFollowSaveDto dto) {
        if(dto.getFocusType().intValue()!=0 && dto.getFocusType().intValue()!=3){
            return R.fail("暂不支持的关注类型");
        }
        int i = followService.addFollow(dto);
        return R.success(i>0 ? true : false);
    }

    @PostMapping(value = "/cancelFollow/{followId}")
    @ApiOperation(value = "取消关注/黑名单", notes = "删除关注/黑名单名单")
    @ApiImplicitParam(name = "followId", value = "关注id", required = true)
    public R<Boolean>  cancelFollow(@PathVariable Long followId) {
        int i = followService.cancelFollow(followId);
        return R.success(i>0 ? true : false);
    }

    @PostMapping(value = "/myFollowsPage")
    @ApiOperation(value = "我的关注列表(好友/黑名单)-分页")
    public R<Page<FollowVo>> myFollowsPage(@RequestBody @Valid PageParams<SocialFollowFriendsQueryDto> pageParams) {
        Page<FollowVo> page = pageParams.buildSimplePage();
        return R.success(followService.myFollowPage(page, pageParams.getModel().getFocusType()));
    }

    @PostMapping(value = "/myFansPage")
    @ApiOperation(value = "我的粉丝列表-分页")
    public R<Page<FollowVo>> myFansPage(@RequestBody @Valid PageParams pageParams) {
        Page<FollowVo> page = pageParams.buildSimplePage();
        return R.success(followService.myFansPage(page));
    }

    @PostMapping(value = "/myFriendsPage")
    @ApiOperation(value = "我的好友列表-分页")
    public R<Page<FollowVo>> myFriendsPage(@RequestBody @Valid PageParams pageParams) {
        Page<FollowVo> page = pageParams.buildSimplePage();
        return R.success(followService.myFriendsPage(page));
    }
}
